<?php
/**
 * Defines the edges cubies
 *
 * @package CubeModel
 * @since   Oct 19, 2006
 * @author  Christophe Thiriot
 */


/**
 * The class of the edges
 *
 * @package CubeModel
*/
class edge extends cubie {
    const MAX_EDGE = 12;

    /**
     * @var integer
     */
    private $orientation;

    /**
     * Constructor
     */
    public function __construct($opos, $orient = 0) {
        parent::__construct(parent::EDGE);
        if (is_numeric($opos) && $opos<=self::MAX_EDGE && $opos>=0) {
        	$this->originPosition = $opos;
        } else {
        	throw new Exception('edge::__construct : Bad edge origin position');
        }
        if ($orient === 0 || $orient === 1) {
            $this->orientation = $orient;
        } else {
            throw new Exception('edge::__construct : Bad edge orientation');
        }
    }

    /**
     * getter
     * @final
     */
    public function getOrientation() {
        return $this->orientation;
    }

    /**
     * Change the state of orientation between 0 (oriented) and 1 (not oriented)
     */
    public function toggleOrientation() {
        if ($this->getOrientation() === 0) {
        	$this->orientation = 1;
        } else {
        	$this->orientation = 0;
        }
    }

    /**
     * generates the string representing the orientation
     */
    public function orientToString() {
        if ($this->getOrientation() === 0) {
            return '';
        } else if ($this->getOrientation() === 1) {
            return '-';
        } else {
            throw new Exception('edge::orientToString : bad orientation');
        }
    }
}
?>